﻿using System;
using System.IO;
using System.Reflection;

namespace WorkFlow
{
    public class LogHelper
    {
        public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("LogInfo");//这里的 LogInfo 和 log4net.config 里的名字要一样
        //public static readonly log4net.ILog loger= log4net.LogManager.GetLogger("logerror");
        public static void Init()
        {
            string assName = Assembly.GetExecutingAssembly().GetName().Name;
            string resXml = assName + ".log4net.xml";
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resXml))
            {
                log4net.Config.XmlConfigurator.Configure(stream);
            }
        }
        public static void WriteLog(string info)
        {
            if (loginfo.IsInfoEnabled)
            {
                loginfo.Info(info);
            }
        }


        public static void WriteLog(string info, Exception ex)
        {
            if (loginfo.IsErrorEnabled)
            {
                loginfo.Error(info, ex);
            }
        }

        public static void WriteLog(Exception ex)
        {
            if (loginfo.IsErrorEnabled)
            {
                loginfo.Error(ex.Message, ex);
            }
        }
    }
}
